package com.example.demo.mapper;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.model.Book;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface BookMapper {
    @Select("SELECT * FROM book WHERE book_id = #{bookId}")
    Book findBookById(Long bookId);

    @Update("UPDATE book SET stock = stock - 1, status = 'BORROWED' WHERE book_id = #{bookId}")
    int borrowBookWithLock(Long bookId);

    @Update("UPDATE book SET stock = stock + 1, status = 'AVAILABLE' WHERE book_id = #{bookId}")
    void returnBook(Long bookId);

    

    IPage<Book> selectPage(Page<Book> bookPage, Object o);

    int insert(Book book);

    int deleteById(Long bookId);

    int updateById(Book book);

    Book selectById(Long bookId);
}